import { createRoot } from 'react-dom/client'
import App from './App'
import React from 'react'
import { api_common, api_permission, api_role } from './apis'
import { dispatch, hasPermission, updatePermission, updateRole } from './store'
import { PermissionKey } from '../server/interface'

const root = document.getElementById('app')

api_common.loginUser(void 0).then(async (res) => {
    if (!res.success) {
        alert(res.msg)
        location.href = '/'
    }
    dispatch(state => {
        return {
            ...state,
            loginUser: res.data,
        }
    })
    root && createRoot(root).render(<App />)

    updatePermission()
    updateRole()
})
